package com.txunda.zhuohired.aty.manage.my;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ants.theantsgo.config.Settings;
import com.ants.theantsgo.imageLoader.GlideImageLoader;
import com.ants.theantsgo.tool.ToolKit;
import com.ants.theantsgo.util.CompressionUtil;
import com.bumptech.glide.Glide;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.lzy.imagepicker.ImagePicker;
import com.lzy.imagepicker.bean.ImageItem;
import com.lzy.imagepicker.ui.ImageGridActivity;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.base.Base2Aty;

import java.io.File;
import java.util.ArrayList;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/14 11:22
 * 功能描述：企业资质
 * 联系方式：jiahuanchen@126.com
 */

public class ManageCompanyAptitudeAty extends Base2Aty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_blue_center)
    private TextView tv_layout_blue_center;
    /**
     * 营业执照
     */
    @ViewInject(R.id.iv_manage_company_aptitude_permit)
    private ImageView iv_manage_company_aptitude_permit;
    /**
     * 身份证
     */
    @ViewInject(R.id.iv_manage_company_aptitude_id_card)
    private ImageView iv_manage_company_aptitude_id_card;
    private File file;
    private File file1;
    private int size = 0;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_blue_head);
        tv_layout_blue_center.setText("企业资质");
    }


    @Override
    @OnClick({R.id.iv_manage_company_aptitude_permit, R.id.iv_manage_company_aptitude_id_card})
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_manage_company_aptitude_permit://营业执照
                startActivityForResult(ImageGridActivity.class, null, 100);
                break;
            case R.id.iv_manage_company_aptitude_id_card://身份证
                startActivityForResult(ImageGridActivity.class, null, 101);
                break;

        }
    }


    @Override
    protected int getLayoutResId() {
        return R.layout.aty_manage_company_aptitude;
    }

    @Override
    protected void initialized() {
        ImagePicker imagePicker = ImagePicker.getInstance();
        imagePicker.setImageLoader(new GlideImageLoader());
        imagePicker.setShowCamera(true);// 显示相机
        imagePicker.setMultiMode(false);
        imagePicker.setCrop(true);
        imagePicker.setFocusHeight(Settings.displayWidth);
        imagePicker.setFocusWidth(Settings.displayWidth);
        imagePicker.setOutPutX(Settings.displayWidth);
        imagePicker.setOutPutY(Settings.displayWidth);
        size = ToolKit.dip2px(this, 68);
    }

    @Override
    protected void requestData() {

    }
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == ImagePicker.RESULT_CODE_ITEMS) {
            if (data != null) {
                ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker
                        .EXTRA_RESULT_ITEMS);
                String pic_path = CompressionUtil.compressionBitmap(images.get(0).path);
                switch (requestCode) {
                    case 100:
                        file = new File(pic_path);
                        Glide.with(this).load(file).override(size, size).centerCrop().into(iv_manage_company_aptitude_permit);
                        break;
                    case 101:
                        file1 = new File(pic_path);
                        Glide.with(this).load(file1).override(size, size).centerCrop().into
                                (iv_manage_company_aptitude_id_card);
                        break;
                }
            } else {
                Toast.makeText(this, "加载出错", Toast.LENGTH_SHORT).show();
            }
        }
    }
}
